function print() {
    $('#creditArea').jqprint();
}

function loadData(param) {
	$.ajax({
		type : "post",
		url : "student/idno/" + param,
		dataType : "json",
        cache: false,
		success : function(data) {
			if (null != data) {
				var studentName = data.name;
				$('#studentName').text(data.name);
				$.ajax({
					type : "post",
					url : "clasz/" + data.executiveClass,
					dataType : "json",
			        cache: false,
					success : function(data1) {
						if(data1 == null) {
							alert("您没有分配具体的行政班级，请首先确认！");
							return;
						}
						if (null != data1) {
							studentClasz = data1.name;
							studentGrade = data1.createYear;
							$('#studentClasz').text(data1.name);
							$('#studentGrade').text(data1.createYear);
							$.ajax({
								type : "post",
								url : "credit/" + data.id,
								dataType : "json",
						        cache: false,
								success : function(data2) {
									var sum1 = 0;
									var sum2 = 0;
									$.each(data2, function(i, item) {
										 if (null != item.elective1) {
						            		 if (item.elective1.isGetCredit == 1) {
													var credit = item.elective1.course.studyCredit;
													sum1 += credit;
											}
					                     }
										 if (null != item.elective2) {
						            		 if (item.elective2.isGetCredit == 1) {
													var credit = item.elective2.course.studyCredit;
													sum2 += credit;
												}
					                     }
									});
									$.ajax({
										type : "post",
										url : "credit/value",
										dataType : "json",
								        cache: false,
										success : function(data3) {
											var content = "";
											if (data3.elective1Credit <= sum1) {
									        	data2.isGet1 = "是";
											} else {
									        	data2.isGet1 = "否";
											}
											if (data3.elective2Credit <= sum2) {
									        	data2.isGet2 = "是";
											} else {
									        	data2.isGet2 = "否";
											}
											data2.allScore = (sum1 + sum2);
											$('#data').datagrid({
										        fitColumns: true,
										        fit: true,
										        rownumbers: false,
										        id:"ID",
										        singleSelect: true,
										        pagination: false,
										        border: true,
										        data: data2,
										        columns: [
										            [
										             { title: '学生个人学分汇总表', align: 'center', colspan:9}
										            ],
										            [
										             {title: '名称', align: 'center'},
											         {title: studentName, align: 'center', colspan:2},
										             {title: '班级', align: 'center'},
											         {title: studentClasz, align: 'center', colspan:2},
										             {title: '年级', align: 'center'},
											         {title: studentGrade, align: 'center', colspan:2}
										             ],
											         [
											          {align: 'center'},
											          {title: '选修I', align: 'center', colspan:3},
											          {align: 'center'},
											          {title: '选修II', align: 'center', colspan:3},
											          {field: 'allScore', title: '总学分', align: 'center', rowspan:2,
											            	 formatter: function (value, row, index) {
																if (index == 0) {
																	content += "<td id='allScores' rowspan=" + data2.length + ">" + data2.allScore + "</td>";
																}
																content += "</tr>";
											                    return data2.allScore;
											            	 }
											             }
											          ],
										            [
										             {field: 'studyArea1', title: '学习领域', align: 'center', width: 100,
										            	 formatter: function (value, row, index) {
										            		 content += "<tr>";
										                     if (null != row.elective1) {
										                    	 var val = row.elective1.course.courseStructure.studyArea;
										                    	 content += "<td>" + val + "</td>";
										                    	 return val;
										                     } else {
										                    	 content += "<td>&nbsp;</td>";
										                     }
										                 }
										             },
										             {field: 'courseName1', title: '课程/模块名称', align: 'center', width: 200,
										            	 formatter: function (value, row, index) {
										                     if (null != row.elective1) {
										                    	 var val = row.elective1.course.courseName + "/" + row.elective1.course.courseStructure.studySubject;
										                    	 content += "<td>" + val + "</td>";
										                    	 return val;
										                     } else {
										                    	 content += "<td>&nbsp;</td>";
										                     }
										                 }
										             },
										             {field: 'credit1', title: '得到学分', align: 'center', width: 80,
										            	 formatter: function(value, row, index) {
										                     if (null != row.elective1) {
											            		 if (row.elective1.isGetCredit == 1) {
																		var credit = row.elective1.course.studyCredit;
																		content += "<td>" + credit + "</td>";
																		return credit;
																} else {
																	content += "<td>0</td>";
																	return '0';
																}
										                     } else {
											            		 content += "<td>&nbsp;</td>";
										                     }
										            	 }
										             },
										             {field: 'isGet1', title: '是否达标', align: 'center',
										            	 formatter: function (value, row, index) {
										                     if (null != row.elective1) {
																if (index == 0) {
																	content += "<td id='isGet1' rowspan=" + data2.length + ">" + data2.isGet1 + "</td>";
																}
										                    	 return data2.isGet1;
										                     } else {
										                    	 if (index == 0) {
																		content += "<td id='isGet1' rowspan=" + data2.length + ">&nbsp;</td>";
										                    	 }
										                     }
										                 }
										             },
										             {field: 'studyArea2', title: '学习领域', align: 'center', width: 100,
										            	 formatter: function (value, row, index) {
										                     if (null != row.elective2) {
										                    	 var val = row.elective2.course.courseStructure.studyArea;
										                    	 content += "<td>" + val + "</td>";
										                    	 return val;
										                     } else {
										                    	 content += "<td>&nbsp;</td>";
										                     }
										                 }
										             },
										             {field: 'courseName2', title: '课程/模块名称', align: 'center', width: 200,
										            	 formatter: function (value, row, index) {
										                     if (null != row.elective2) {
										                    	 var val = row.elective2.course.courseName + "/" + row.elective2.course.courseStructure.studySubject;
										                    	 content += "<td>" + val + "</td>";
										                    	 return val;
										                     } else {
										                    	 content += "<td>&nbsp;</td>";
										                     }
										                 }
										             },
										             {field: 'credit2', title: '得到学分', align: 'center', width: 150,
										            	 formatter: function(value, row, index) {
										                     if (null != row.elective2) {
											            		 if (row.elective2.isGetCredit == 1) {
																		var credit = row.elective2.course.studyCredit;
																		content += "<td>" + credit + "</td>";
																		return credit;
																} else {
												            		 content += "<td>0</td>";
												            		 return '0';
																}
										                     } else {
											            		 content += "<td>&nbsp;</td>";
										                     }
										            	 }
										              },
										             {field: 'isGet2', title: '是否达标', align: 'center',
											            	 formatter: function (value, row, index) {
											                     if (null != row.elective2) {
																		if (index == 0) {
																			content += "<td id='isGet2' rowspan=" + data2.length + ">" + data2.isGet2 + "</td>";
																		}
											                    	 return data2.isGet2;
											                     } else {
											                    	 if (index == 0) {
																			content += "<td id='isGet2' rowspan=" + data2.length + ">&nbsp;</td>";
											                    	 }
											                     }
											                 }
											              }
										            ]
										        ],
										        rowStyler: function(index,row){  
										            if (index % 2 == 1){  
										                return 'background-color:#FFF8DC;';  
										            }  
										        },
										        onLoadSuccess: function() {
										        	$('#printData').append(content);
										        	var merges = [{
										                index: 0,
										                field: 'isGet1',
										                rowspan: data2.length
										            },{
										                index: 0,
										                field: 'isGet2',
										                rowspan: data2.length
										            },{
										                index: 0,
										                field: 'allScore',
										                rowspan: data2.length
										            }];
										            for(var i=0; i<merges.length; i++){
										                $('#data').datagrid('mergeCells',{
										                    index: merges[i].index,
										                    field: merges[i].field,
										                    rowspan: merges[i].rowspan
										                });
										            }
										        }
											});
										}
									});
								}
							});
						}
					}
				});
			}
		}
	});
}
